package com.material.web.controller.factory;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.material.common.annotation.Log;
import com.material.common.core.controller.BaseController;
import com.material.common.core.domain.AjaxResult;
import com.material.common.enums.BusinessType;
import com.material.factory.domain.FactoryCategory;
import com.material.factory.service.IFactoryCategoryService;
import com.material.common.utils.poi.ExcelUtil;
import com.material.common.core.page.TableDataInfo;

/**
 * 工厂类别Controller
 * 
 * @author ruoyi
 * @date 2025-05-07
 */
@RestController
@RequestMapping("/factory/category")
public class FactoryCategoryController extends BaseController
{
    @Autowired
    private IFactoryCategoryService factoryCategoryService;

    /**
     * 查询工厂类别列表
     */
    @PreAuthorize("@ss.hasPermi('factory:category:list')")
    @GetMapping("/list")
    public TableDataInfo list(FactoryCategory factoryCategory)
    {
        startPage();
        List<FactoryCategory> list = factoryCategoryService.selectFactoryCategoryList(factoryCategory);
        return getDataTable(list);
    }

    /**
     * 导出工厂类别列表
     */
    @PreAuthorize("@ss.hasPermi('factory:category:export')")
    @Log(title = "工厂类别", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FactoryCategory factoryCategory)
    {
        List<FactoryCategory> list = factoryCategoryService.selectFactoryCategoryList(factoryCategory);
        ExcelUtil<FactoryCategory> util = new ExcelUtil<FactoryCategory>(FactoryCategory.class);
        util.exportExcel(response, list, "工厂类别数据");
    }

    /**
     * 获取工厂类别详细信息
     */
    @PreAuthorize("@ss.hasPermi('factory:category:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(factoryCategoryService.selectFactoryCategoryById(id));
    }

    /**
     * 新增工厂类别
     */
    @PreAuthorize("@ss.hasPermi('factory:category:add')")
    @Log(title = "工厂类别", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FactoryCategory factoryCategory)
    {
        return toAjax(factoryCategoryService.insertFactoryCategory(factoryCategory));
    }

    /**
     * 修改工厂类别
     */
    @PreAuthorize("@ss.hasPermi('factory:category:edit')")
    @Log(title = "工厂类别", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FactoryCategory factoryCategory)
    {
        return toAjax(factoryCategoryService.updateFactoryCategory(factoryCategory));
    }

    /**
     * 删除工厂类别
     */
    @PreAuthorize("@ss.hasPermi('factory:category:remove')")
    @Log(title = "工厂类别", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(factoryCategoryService.deleteFactoryCategoryByIds(ids));
    }
}
